<template>
  <input ref="autoFocusInput" v-model="inputValue" placeholder="请输入内容" />
</template>

<script setup lang="ts">
import { nextTick, onMounted, ref } from 'vue'

const inputValue = ref<string>('')

const autoFocusInput = ref<null | HTMLInputElement>(null)

onMounted(async () => {
  // 确保dom准备好后执行以下操作
  await nextTick()

  // autoFocusInput.value?.focus()
  if (autoFocusInput.value) {
    autoFocusInput.value.focus()
  }
})
</script>
